package
{
import mx.controls.DataGrid;
import mx.controls.dataGridClasses.DataGridItemRenderer;
import mx.controls.dataGridClasses.DataGridListData;

public class DeepDataGridItemRenderer extends DataGridItemRenderer
{

	public function DeepDataGridItemRenderer()
	{
		super();
	}

	/**
	 *  This is evil, but the DG never reads back the listData.label
	 *  so we'll just fix it up when set.
	 */
	override public function validateProperties():void
	{
		if (!listData) 
		{
			// item renderers are recycled so you have to make sure
			// that all code paths lead to a known state.
			return super.validateProperties();
		}

		var dgListData:DataGridListData = listData as DataGridListData;
		var dataGrid:DataGrid = dgListData.owner as DataGrid;
		var column:DeepDataGridColumn = dataGrid.columns[dgListData.columnIndex];
		var fields:Array = column.deepDataField.split('.');
		var lastField:String = fields.pop();
		var o:Object = data;
		var n:int = fields.length;
		for (var i:int = 0; i < n; i++)
			o = o[fields[i]];
		listData.label = o[lastField].toString();

		super.validateProperties();
	}

}

}